package com.elvis.abstractdocument;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * Created by zengqiang04 on 2017/9/27.
 */
public abstract class AbstractDocument implements Document{

    private final Map<String, Object> properties;

    protected AbstractDocument(Map<String, Object> properties) {
        Objects.requireNonNull(properties, "properties map is required");
        this.properties = properties;
    }

    @Override
    public Void put(String key, Object value) {
        properties.put(key, value);
        return null;
    }

    @Override
    public Object get(String key) {
        return properties.get(key);
    }

    @Override
    public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {

        Optional<Map<String, Object>>

        return null;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getName()).append("[");

        properties.entrySet().stream()
                .forEach(e -> sb.append("[").append(e.getKey()).append(" : ")
                .append(e.getValue()).append("]"));

        sb.append("]");
        return sb.toString();
    }
}
